<template>
  <div>
    <el-dialog title="" :visible.sync="dialogSkuVisible" :close-on-press-escape="true" width="850px">
      <div class="goods-layer pad-l-20 pad-r-20 pad-b-20">
        <h3>多规格商品活动设置</h3>
        <div class="flex v-align-c cursor-p">
          <label><img :src="goodsInfo.imageUrl" class="picture-avatar"></label>
          <div class="font-14 pad-l-10">
            <div class="title-line-2 font-14 width-300">{{goodsInfo.title}}</div>
            <template>
              <div>
                <span class="category-style">{{goodsInfo.categoryName}}</span>
                <el-tag class="mar-l-10" size="mini" effect="light">多规格</el-tag>
              </div>
            </template>
          </div>
        </div>

        <div class="table-container pad-t-20 pad-b-20" v-loading="skuLoading">
          <div
            class="el-table el-table--fit el-table--border el-table--enable-row-hover el-table--medium el-table--scrollable-x">
            <div class="el-table__body-wrapper">
              <table cellspacing="0" cellpadding="0" border="0" class="el-table__body" style="width: 100%;">
                <thead class="el-table__header">
                <tr>
                  <th>
                    <div class="cell text-align-c">规格</div>
                  </th>
                  <th>
                    <div class="cell text-align-c">零售价</div>
                  </th>
                  <th>
                    <div class="cell text-align-c">库存</div>
                  </th>
                  <th width="145">
                    <div class="cell text-align-c">
                      <el-popover :disabled="disabledBoolean"
                        placement="top"
                        width="160"
                        v-model="visiblePopPrice">
                        <div class="text-align-c pad-b-10">批量设置</div>
                        <el-form label-position="right" style='width: 100%;'>
                          <el-form-item>
                            <el-input v-model="skuParamSettingValue" type="number"/>
                          </el-form-item>
                        </el-form>
                        <div class="mar-t--10" style="text-align: right;">
                          <el-button size="mini" type="text" @click="visiblePopPrice = false">取消</el-button>
                          <el-button type="primary" size="mini" @click="setAllPrice">确定</el-button>
                        </div>
                        <label slot="reference">
                          <span>活动价</span>
                          <i class="el-icon-circle-plus mar-l-10 font-blue"></i>
                        </label>
                      </el-popover>
                    </div>
                  </th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="(item, index) in goodsInfo.promotionGoodsSkuList" :key="index">
                  <td>
                    <div class="cell text-align-c">
                      {{item.skuDetail}}
                    </div>
                  </td>
                  <td>
                    <div class="cell text-align-c">
                      ￥{{item.price}}
                    </div>
                  </td>
                  <td>
                    <div class="cell text-align-c">
                      {{item.stock}}
                    </div>
                  </td>
                  <td>
                    <div class="cell text-align-c">
                      <el-input v-model="item.promotionPrice" min="0" placeholder="请输入活动价" :disabled="disabledBoolean"></el-input>
                    </div>
                  </td>
                </tr>
                </tbody>
              </table>
            </div>
          </div>
        </div>
        <div class="height-36"></div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogSkuVisible = false">取消</el-button>
          <el-button type="primary" @click="sureOk">确定</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import goodsDefaultOne from '@/assets/images/goods-1.png'
  import goodsDefaultTwo from '@/assets/images/goods-2.png'

  export default {
    props: {
      disabledBoolean: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        goodsInfo: {},
        goodsDefaultOne: goodsDefaultOne,
        goodsDefaultTwo: goodsDefaultTwo,
        selectLoading: true,
        selectList: [],
        dialogSkuVisible: false,
        skuLoading: false,
        visiblePopPrice: false,
        skuParamSettingValue: ''
      }
    },
    // 初始化页面
    created() {
      console.log('sku-price')
    },
    mounted() {
      const that = this
      this.$bus.$on('promotion-sku-price-open', function(row) {
        const goodsInfo = JSON.parse(JSON.stringify(row))
        that.goodsInfo = goodsInfo
        that.dialogSkuVisible = true
      })
    },
    filters: {
    },
    methods: {
      setActivePrice() {
        this.dialogSkuVisible = true
        this.skuLoading = true
        setTimeout(() => {
          this.skuLoading = false
        }, 800)
      },
      sureOk() {
        this.dialogSkuVisible = false
        const goodsInfo = this.goodsInfo
        const dataList = goodsInfo.promotionGoodsSkuList
        var patt1 = new RegExp(/^([1-9]\d*(\.\d*[1-9][0-9])?)|(0\.\d*[1-9][0-9])|(0\.\d*[1-9])$/)
        dataList.forEach(obj => {
          const promotionPrice = obj.promotionPrice
          if (!this.$utils.isExist(promotionPrice)) {
            this.$message({ message: '活动价格不能为空', type: 'error' })
          }
          const fee = (promotionPrice * 1).toFixed(2)
          if (!patt1.test(fee)) {
            this.$message.error('请正确输入商品价格!')
            return
          }
          obj.promotionPrice = fee
        })
        this.$bus.$emit('promotion-sku-price-save', goodsInfo)
      },
      setAllPrice() {
        const skuParamSettingValue = this.skuParamSettingValue
        if (skuParamSettingValue === '') {
          return
        }
        this.visiblePopPrice = false
        const goodsInfo = this.goodsInfo
        const dataList = goodsInfo.promotionGoodsSkuList
        dataList.forEach(obj => {
          const fee = (skuParamSettingValue * 1).toFixed(2)
          this.$set(obj, 'promotionPrice', fee)
        })
      }
    }
  }
</script>
<style lang="less" scoped>
  // 页面总体布局
  .active-main{
    background: #f8f8f8;
    &:after{
      content: '';
      display: block;
      clear: both;
      font-size: 0;
    }
    .active-l{
      .main-content{
        padding-right: 4px;
        padding-left: 2px;
        height: 570px;
        overflow-x: hidden;
        overflow-y: auto;
        &::-webkit-scrollbar {
          width: 4px;
        }
        &::-webkit-scrollbar-thumb {
          border-radius: 10px;
          box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
          -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
          background: rgba(0,0,0,0.2);
        }
        &::-webkit-scrollbar-track {
          box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
          -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
          border-radius: 0;
          background: rgba(0,0,0,0.1);
        }
        h2{
          margin: 0;
          font-size: 18px;
        }
        ul{
          padding: 0;
          margin: 0;
          &:after{
            content: '';
            display: block;
            clear: both;
            font-size: 0;
          }
          &.show-type-1{
            li{
              .gooods-pic{
                img{
                  width: 100%;
                  height: 149px;
                  border-top-left-radius: 4px;
                  border-top-right-radius: 4px;
                }
              }
            }
          }
          &.show-type-2{
            li{
              width: 48%;
              float: left;
              &:nth-child(odd){
                margin-right: 4%;
              }
              .gooods-pic{
                img{
                  width: 100%;
                  height: 133px;
                  border-top-left-radius: 4px;
                  border-top-right-radius: 4px;
                }
              }
              .buy-now-type{
                display: none;
              }
              .price{
                label{
                  display: none;
                }
              }
            }
          }
          &.show-type-3{
            li{
              display: -webkit-box;
              display: -webkit-flex;
              display: flex;
              flex-flow: row;
              align-items: center;
              padding: 0 5px 0 8px;
              .pic-box{
                margin-right: 6px;
                .gooods-pic{
                  img{
                    width: 82px;
                    height: 82px;
                  }
                }
              }
              .detail-box{
                -webkit-box-flex: 1;
                -webkit-flex: 1;
                flex: 1;
              }
              .tag{
                span{
                  padding: 1px 5px!important;
                }
                label{
                  padding: 1px 5px!important;
                }
              }
              .price{
                label{
                  display: none;
                }
              }
              .stock{
                display: none;
              }
            }
          }
          &.show-type-4{
            li{
              display: -webkit-box;
              display: -webkit-flex;
              display: flex;
              flex-flow: row;
              align-items: center;
              padding: 8px 5px 8px 8px;
              &:nth-child(even){
                .pic-box{
                  &.even{
                    display: none;
                  }
                  &.odd{
                    display: block;
                  }
                }
              }
              &:nth-child(odd){
                .pic-box{
                  &.even{
                    display: block;
                  }
                  &.odd{
                    display: none;
                  }
                }
              }
              .pic-box{
                margin-right: 6px;
                .gooods-pic{
                  img{
                    width: 122px;
                    height: 122px;
                  }
                }
              }
              .detail-box{
                -webkit-box-flex: 1;
                -webkit-flex: 1;
                flex: 1;
                padding: 0 6px!important;
              }
              .desc{
                margin-top: -6px;
              }
              .tag{
                margin-top: -1px;
                margin-bottom: 0px;
                span{
                  padding: 1px 5px!important;
                }
                label{
                  padding: 1px 5px!important;
                }
              }
              .price{
                .flex-item{
                  >label{
                    display: -webkit-box;
                    display: -webkit-flex;
                    display: flex;
                    margin-top: -8px;
                  }
                }
              }
              .stock{
                display: none;
              }
              .info-bar{
                .buy-now-type{
                  display: none!important;
                }
              }
              .last-item{
                display: block!important;
                margin-top: 5px;
              }
            }
          }
          li{
            list-style-type: none;
            border-radius: 4px;
            box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
            margin-bottom: 15px;
            &:last-child{
              margin-bottom: 0;
            }
            .pic-box{
              &.odd{
                display: none;
              }
            }
            .gooods-pic{
              img{
                display: block;
              }
            }
            .desc{
              height: 36px;
              line-height: 1.5;
              overflow:hidden;
              text-overflow:ellipsis;
              display:-webkit-box;
              -webkit-line-clamp:2;
              -webkit-box-orient:vertical;
              word-break:break-word;
            }
            .last-item{
              display: none;
            }
            .info-bar{
              .tag{
                line-height: 1.3;
                span{
                  background: #fed807;
                  color: #333;
                  padding: 2px 5px;
                }
                label{
                  background: #272727;
                  color: #fff;
                  padding: 2px 5px;
                  min-width: 60px;
                  box-sizing: border-box;
                  i{
                    color: #ffc81b;
                    font-style: normal;
                  }
                }
              }
              .price{
                span{
                  color: #FF4949;
                }
                label{
                  text-decoration: line-through;
                }
              }
              .stock{
                color: #6e6e6e;
              }
              label{
                font-weight: normal;
              }
            }
          }
        }
        .picture-default{
          background: #fe8096;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
    }
    .active-r{
      border: 1px solid #ddd;
      border-radius: 10px;
      background: #fff;
      padding: 20px;
      min-height: 609px;
      h2{
        font-size: 18px;
        margin: 0;
      }
      .tips{
        color: #409eff;
      }
      .select-table{
        min-height: auto!important;
      }
    }
  }
  .category-style {
    color: #6290ff;
    font-size: 13px;
  }
  .title-line-2{
    height: 40px;
    line-height: 1.4;
    overflow:hidden;
    text-overflow:ellipsis;
    display:-webkit-box;
    -webkit-line-clamp:2;
    -webkit-box-orient:vertical;
    word-break:break-word;
  }
  // 商品弹窗样式
  .goods-layer{
    h3{
      margin: -10px 0 0 0;
      color: #303133;
      font-size: 18px;
      text-align: center;
    }
    .dialog-footer{
      position: absolute;
      left: 0;
      bottom: 20px;
      width: 100%;
    }
    .table-container{
      height: 500px;
      overflow-x: hidden;
      overflow-y: auto;
    }
  }
  // 左侧手机模型样式
  .diy-bg-main{
    .diy-phone {
      float: left;
      width: 340px;
      border: 1px solid #ddd;
      border-radius: 10px;
      background: #fff;
      padding: 10px;
      overflow: hidden;
      &.none-border{
        border: none;
        background: none;
        padding: 0px 10px;
        border-radius: 0;
      }
    }
    .diy-phone .phone-head {
      height: 44px;
      background: #fff;
      position: relative;
    }
    .diy-phone .phone-head:before {
      content: "";
      position: absolute;
      top: 15px;
      left: 112px;
      height: 8px;
      width: 8px;
      background: #ddd;
      border-radius: 8px;
    }
    .diy-phone .phone-head:after {
      content: "";
      position: absolute;
      top: 15px;
      left: 128px;
      height: 8px;
      width: 50px;
      background: #ddd;
      border-radius: 8px;
    }
    .diy-phone .phone-title {
      height: 17px;
      /*background: url(../../../../assets/images/wx-top-2.png) 0 0 no-repeat;*/
      background-size: 100% auto;
      padding: 0 50px;
      font-size: 15px;
      color: #333333;
      text-align: center;
      line-height: 68px;
      cursor: default;
      overflow: hidden;
      display: block;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
  }
</style>
